package com.dissertation.model.auth;

import com.dissertation.model.MongodbBaseModel;
import com.dissertation.utils.MD5Util;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.constraints.NotNull;
import java.util.*;

/**
 * unique_name是账号
 */
@Document
public class User extends MongodbBaseModel {


    private String name;//当前登录人姓名

    private String password;

    @NotNull
    private Set<Role> role;

    private boolean isSecurity; // 是否安全 （是否修改过密码）

    public String getPassword() {
        return password;
    }

    public void setPassword( String password ) {
        this.password = password;
    }

    public Set<Role> getRole() {
        return role;
    }

    public void setRole( Set<Role> role ) {
        this.role = role;
    }

    public void addRoles( Role... roles ) {
        role = Optional.ofNullable( role ).orElse( new HashSet<>() );
        role.addAll( Arrays.asList( roles ) );
    }

    public boolean isSecurity() {
        return isSecurity;
    }

    public void setSecurity( boolean security ) {
        isSecurity = security;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {

        return name;
    }
}
